package cn.zwx.remoting.netty;

import cn.zwx.exception.RemotingConnectException;
import cn.zwx.exception.RemotingSendRequestException;
import cn.zwx.remoting.RemotingCommand;
import cn.zwx.exception.RemotingTimeoutException;

/**
 * RPC client端调用接口
 * @author 105286
 */
public interface RemotingClient extends RemotingService{


    /**
     *  同步调用
     * @param addr 地址
     * @param command  command
     * @param timeoutMillis 超时时间
     * @return RemotingCommand
     * @author zhangwenxue
     * @createTime 2022/6/20 14:42
     * @throws InterruptedException 阻塞异常
     * @throws RemotingSendRequestException 远程调用异常
     * @throws RemotingSendRequestException 发送远程调用异常
     * @throws RemotingTimeoutException 超时异常
     * @throws RemotingConnectException 连接异常
     **/
    RemotingCommand invokeSync(final String addr, final RemotingCommand command, final long timeoutMillis)
            throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException, RemotingConnectException;


    /**
     * 远程连接服务器
     * @param ip   服务器地址
     * @param port 服务器端口
     */
    void connect(String ip, int port);


    /**
     * 对应的key的通道是否活跃状态
     * @param key key
     * @return boolean
     */
    boolean channelActive(String key);
}
